/**
 * DragonBones Types
 * 
 * Type definitions for the DragonBones animation system
 */

// DragonBones数据结构接口
export interface DragonBonesData {
  name: string;
  version: string;
  frameRate: number;
  armature: ArmatureData[];
  [key: string]: any;
}

export interface ArmatureData {
  name: string;
  bone: BoneData[];
  slot: SlotData[];
  skin: SkinData[];
  animation: AnimationData[];
  [key: string]: any;
}

export interface BoneData {
  name: string;
  parent?: string;
  transform?: TransformData;
  [key: string]: any;
}

export interface SlotData {
  name: string;
  parent: string;
  display: DisplayData[];
  [key: string]: any;
}

export interface DisplayData {
  name: string;
  type: string;
  path?: string;
  [key: string]: any;
}

export interface SkinData {
  name: string;
  slot: SkinSlotData[];
  [key: string]: any;
}

export interface SkinSlotData {
  name: string;
  display: DisplayDisplayData[];
  [key: string]: any;
}

export interface DisplayDisplayData {
  name: string;
  type: string;
  path?: string;
  transform?: TransformData;
  [key: string]: any;
}

export interface AnimationData {
  name: string;
  duration: number;
  playTimes: number;
  bone: AnimationBoneData[];
  slot: AnimationSlotData[];
  [key: string]: any;
}

export interface AnimationBoneData {
  name: string;
  translateFrame?: TranslateFrameData[];
  rotateFrame?: RotateFrameData[];
  scaleFrame?: ScaleFrameData[];
  [key: string]: any;
}

export interface AnimationSlotData {
  name: string;
  displayFrame?: DisplayFrameData[];
  [key: string]: any;
}

export interface TranslateFrameData {
  duration: number;
  x: number;
  y: number;
  [key: string]: any;
}

export interface RotateFrameData {
  duration: number;
  rotate: number;
  [key: string]: any;
}

export interface ScaleFrameData {
  duration: number;
  x: number;
  y: number;
  [key: string]: any;
}

export interface DisplayFrameData {
  duration: number;
  value: number;
  [key: string]: any;
}

export interface TransformData {
  x?: number;
  y?: number;
  skX?: number;
  skY?: number;
  scX?: number;
  scY?: number;
  [key: string]: any;
}

// 纹理图集接口
export interface TextureAtlasData {
  imagePath: string;
  SubTexture: SubTextureData[];
  [key: string]: any;
}

export interface SubTextureData {
  name: string;
  x: number;
  y: number;
  width: number;
  height: number;
  frameX?: number;
  frameY?: number;
  frameWidth?: number;
  frameHeight?: number;
  [key: string]: any;
}

// 骨架和动画接口
export interface Armature {
  name: string;
  bones: Map<string, Bone>;
  slots: Slot[];
  animations: Map<string, Animation>;
  currentAnimation: Animation | null;
  [key: string]: any;
}

export interface Bone {
  name: string;
  parent: Bone | null;
  transform: Transform;
  globalTransform: Transform;
  [key: string]: any;
}

export interface Slot {
  name: string;
  parent: Bone;
  display: Display;
  displays: Display[];
  [key: string]: any;
}

export interface Display {
  name: string;
  type: string;
  path?: string;
  texture?: any; // Canvas Image对象
  transform?: Transform;
  [key: string]: any;
}

export interface Animation {
  name: string;
  duration: number;
  playTimes: number;
  boneTimelines: Map<string, BoneTimeline>;
  slotTimelines: Map<string, SlotTimeline>;
  currentTime: number;
  [key: string]: any;
}

export interface BoneTimeline {
  bone: Bone;
  translateFrames: TranslateFrame[];
  rotateFrames: RotateFrame[];
  scaleFrames: ScaleFrame[];
  [key: string]: any;
}

export interface SlotTimeline {
  slot: Slot;
  displayFrames: DisplayFrame[];
  [key: string]: any;
}

export interface TranslateFrame {
  duration: number;
  position: { x: number; y: number };
  [key: string]: any;
}

export interface RotateFrame {
  duration: number;
  rotation: number;
  [key: string]: any;
}

export interface ScaleFrame {
  duration: number;
  scale: { x: number; y: number };
  [key: string]: any;
}

export interface DisplayFrame {
  duration: number;
  displayIndex: number;
  [key: string]: any;
}

export interface Transform {
  x: number;
  y: number;
  rotation: number;
  scaleX: number;
  scaleY: number;
  [key: string]: any;
}

// 工厂接口
export interface DragonBonesFactory {
  dragonBonesDataMap: Map<string, DragonBonesData>;
  textureAtlasDataMap: Map<string, TextureAtlasData>;
  parseDragonBonesData(data: DragonBonesData, name?: string): void;
  buildArmature(armatureName: string, dragonBonesName?: string): Armature | null;
  getArmatureNames(dragonBonesName?: string): string[];
  [key: string]: any;
}